<!DOCTYPE html>
<html>
<head>
    <title>Admin Dashboard</title>
    <link rel="stylesheet" href="/static/admin.css">
    <script src="/static/admin.js"></script>
</head>
<body>
<h2>在线用户</h2>
<ul>
    {% for user in online_users %}
        <li>{{ user }}</li>
    {% endfor %}
</ul>

<h2>线程管理</h2>
<table>
    <thead>
    <tr>
        <th>用户名</th>
        <th>线程状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    {% for username, thread in threads.items() %}
        <tr>
            <td>{{ username }}</td>
            <td id="status-{{ username }}">正在运行...</td>
            <td>
                <button onclick="stopThread('{{ username }}')">停止</button>
                <a href="/admin/user_history/{{ username }}" class="btn">查看日志</a>
            </td>
        </tr>
    {% endfor %}
    </tbody>
</table>
<h2>All Users</h2>
<ul id="userList"></ul>

<script>
    fetch('/admin/all_users')
        .then(response => response.json())
        .then(data => {
            const userList = document.getElementById('userList');
            data.forEach(user => {
                let li = document.createElement('li');
                let a = document.createElement('a');
                a.href = `/admin/user_history/${user}`;
                a.innerText = user;
                li.appendChild(a);
                userList.appendChild(li);
            });
        })
        .catch(error => console.error('Error:', error));
</script>
</body>
</html>
